from django.db import models

class Author(models.Model):
    name = models.CharField(max_length=100,null=False)

class bookname(models.Model):
    name = models.CharField(max_length=100,null=False)
    content = models.TextField()
    #on_delete 设置父表删除子表数据处理方式,  models.CASCADE代表父表删除,子表里面也删除相关
    #Author影响bookname
    Author = models.ForeignKey('Author',on_delete=models.CASCADE)
    cate = models.ForeignKey('frontname.Types',on_delete=models.CASCADE,null=True)

    def __srt__(self):
        return "<bookname:(id:%s,name:%s,content:%s)>" % (self.id,self.name,self.content)

#外键连接本身id
# class A(models.Model):
#     name = models.TextField()
#     o_demo  = models.ForeignKey('self',on_delete=models.CASCADE)
